package utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/7
 * Time:20:57
 **/
public class ResultUtils {
    /**
     * write接口的通用方法
     * @param response
     * @param data
     * @throws IOException
     */
    public static void write(HttpServletResponse response,HashMap<String,Object> data) throws IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        PrintWriter writer = response.getWriter();
        ObjectMapper mapper = new ObjectMapper();
        writer.println(mapper.writeValueAsString(data));
    }
}
